New functions to support themed drag icons. (#116577, Christian Neumair)
authorMatthias Clasen <mclasen@redhat.com>
Wed, 18 May 2005 05:23:59 +0000 (05:23 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 18 May 2005 05:23:59 +0000 (05:23 +0000)
2005-05-18  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkdnd.h:
* gtk/gtkdnd.c (gtk_drag_source_set_icon_name)
(gtk_drag_set_icon_name): New functions to support themed
drag icons.  (#116577, Christian Neumair)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtkdnd.c
gtk/gtkdnd.h

index 1b068adb8ab407d8c5b7de5ca69df4dad66079b5..49eab1da4d0d7762855d2814b03ab56c57bee179 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-05-18  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkdnd.h: 
+       * gtk/gtkdnd.c (gtk_drag_source_set_icon_name) 
+       (gtk_drag_set_icon_name): New functions to support themed 
+       drag icons.  (#116577, Christian Neumair)
+
 2005-05-17  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkdrawable-x11.c (gdk_x11_ref_cairo_surface): 
index 1b068adb8ab407d8c5b7de5ca69df4dad66079b5..49eab1da4d0d7762855d2814b03ab56c57bee179 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-18  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkdnd.h: 
+       * gtk/gtkdnd.c (gtk_drag_source_set_icon_name) 
+       (gtk_drag_set_icon_name): New functions to support themed 
+       drag icons.  (#116577, Christian Neumair)
+
 2005-05-17  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkdrawable-x11.c (gdk_x11_ref_cairo_surface): 
index 1b068adb8ab407d8c5b7de5ca69df4dad66079b5..49eab1da4d0d7762855d2814b03ab56c57bee179 100644 (file)
@@ -1,3 +1,11 @@
+2005-05-18  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk.symbols: 
+       * gtk/gtkdnd.h: 
+       * gtk/gtkdnd.c (gtk_drag_source_set_icon_name) 
+       (gtk_drag_set_icon_name): New functions to support themed 
+       drag icons.  (#116577, Christian Neumair)
+
 2005-05-17  Owen Taylor  <otaylor@redhat.com>
 
        * gdk/x11/gdkdrawable-x11.c (gdk_x11_ref_cairo_surface): 
index 650c58dc08cb46fad92a6a9e6c00cb8dba77a2db..d1e5c3c9b888b850e13a294318bcfa5030dd9af8 100644 (file)
@@ -1,3 +1,7 @@
+2005-05-18  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk-sections.txt: Add new functions.
+
 2005-05-16  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/tree_widget.sgml: Use gtk-doc abbrevs instead of 
index 983fccbf8e0d9daff808419cfd1685f692f54e38..2f5cb7a7e913d46aa29d28fb6d9866607bdd1d33 100644 (file)
@@ -5159,6 +5159,7 @@ gtk_drag_set_icon_widget
 gtk_drag_set_icon_pixmap
 gtk_drag_set_icon_pixbuf
 gtk_drag_set_icon_stock
+gtk_drag_set_icon_name
 gtk_drag_set_icon_default
 gtk_drag_set_default_icon
 gtk_drag_check_threshold
@@ -5166,6 +5167,7 @@ gtk_drag_source_set
 gtk_drag_source_set_icon
 gtk_drag_source_set_icon_pixbuf
 gtk_drag_source_set_icon_stock
+gtk_drag_source_set_icon_name
 gtk_drag_source_unset
 gtk_drag_source_set_target_list
 gtk_drag_source_get_target_list
index 2a069add481b2b959aa2830c2d9cb00ded8b0fde..3bb417abfd2691c80865a2e326f268ea7d856d37 100644 (file)
@@ -946,6 +946,7 @@ gtk_drag_highlight
 gtk_drag_set_default_icon
 #endif
 gtk_drag_set_icon_default
+gtk_drag_set_icon_name
 gtk_drag_set_icon_pixbuf
 gtk_drag_set_icon_pixmap
 gtk_drag_set_icon_stock
@@ -956,6 +957,7 @@ gtk_drag_source_add_uri_targets
 gtk_drag_source_get_target_list
 gtk_drag_source_set
 gtk_drag_source_set_icon
+gtk_drag_source_set_icon_name
 gtk_drag_source_set_icon_pixbuf
 gtk_drag_source_set_icon_stock
 gtk_drag_source_set_target_list
index dec51ecff4e61ec0f21e73575c80aa4dc2eab532..db9ccca27f88babb73ba9e8d94406c24e5b31852 100644 (file)
@@ -30,6 +30,8 @@
 #include "gdk/gdkkeysyms.h"
 
 #include "gtkdnd.h"
+#include "gtkiconfactory.h"
+#include "gtkicontheme.h"
 #include "gtkimage.h"
 #include "gtkinvisible.h"
 #include "gtkmain.h"
@@ -68,6 +70,7 @@ struct _GtkDragSourceSite
     GtkImagePixmapData pixmap;
     GtkImagePixbufData pixbuf;
     GtkImageStockData stock;
+    GtkImageIconNameData name;
   } icon_data;
   GdkBitmap *icon_mask;
 
@@ -2046,6 +2049,11 @@ gtk_drag_begin_internal (GtkWidget         *widget,
                                     site->icon_data.stock.stock_id,
                                     -2, -2);
            break;
+         case GTK_IMAGE_ICON_NAME:
+           gtk_drag_set_icon_name (context,
+                                   site->icon_data.name.icon_name,
+                                   -2, -2);
+           break;
          case GTK_IMAGE_EMPTY:
          default:
            g_assert_not_reached();
@@ -2355,6 +2363,9 @@ gtk_drag_source_unset_icon (GtkDragSourceSite *site)
     case GTK_IMAGE_STOCK:
       g_free (site->icon_data.stock.stock_id);
       break;
+    case GTK_IMAGE_ICON_NAME:
+      g_free (site->icon_data.name.icon_name);
+      break;
     default:
       g_assert_not_reached();
       break;
@@ -2462,6 +2473,34 @@ gtk_drag_source_set_icon_stock (GtkWidget   *widget,
   site->icon_data.stock.stock_id = g_strdup (stock_id);
 }
 
+/**
+ * gtk_drag_source_set_icon_name:
+ * @widget: a #GtkWidget
+ * @icon_name: name of icon to use
+ * 
+ * Sets the icon that will be used for drags from a particular source
+ * to a themed icon. See the docs for #GtkIconTheme for more details.
+ *
+ * Since: 2.8
+ **/
+void 
+gtk_drag_source_set_icon_name (GtkWidget   *widget,
+                              const gchar *icon_name)
+{
+  GtkDragSourceSite *site;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (icon_name != NULL);
+
+  site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
+  g_return_if_fail (site != NULL);
+
+  gtk_drag_source_unset_icon (site);
+
+  site->icon_type = GTK_IMAGE_ICON_NAME;
+  site->icon_data.name.icon_name = g_strdup (icon_name);
+}
+
 static void
 gtk_drag_get_icon (GtkDragSourceInfo *info,
                   GtkWidget        **icon_window,
@@ -2782,6 +2821,56 @@ gtk_drag_set_icon_pixmap (GdkDragContext    *context,
   gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
 }
 
+/**
+ * gtk_drag_set_icon_name:
+ * @context: the context for a drag. (This must be called 
+ *            with a context for the source side of a drag)
+ * @icon_name: name of icon to use
+ * @hot_x: the X offset of the hotspot within the icon
+ * @hot_y: the Y offset of the hotspot within the icon
+ * 
+ * Sets the icon for the window from a named themed icon. See
+ * the docs for #GtkIconTheme for more details. Note that the
+ * size of the icon depends on the icon theme (the icon is
+ * loaded at the symbolic size #GTK_ICON_SIZE_DND), thus 
+ * @hot_x and @hot_y have to be used with care.
+ *
+ * Since: 2.8
+ **/
+void 
+gtk_drag_set_icon_name (GdkDragContext *context,
+                       const gchar    *icon_name,
+                       gint            hot_x,
+                       gint            hot_y)
+{
+  GdkScreen *screen;
+  GtkSettings *settings;
+  GtkIconTheme *icon_theme;
+  GdkPixbuf *pixbuf;
+  gint width, height, icon_size;
+
+  g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+  g_return_if_fail (context->is_source);
+  g_return_if_fail (icon_name != NULL);
+
+  screen = gdk_drawable_get_screen (context->source_window);
+  g_return_if_fail (screen != NULL);
+
+  settings = gtk_settings_get_for_screen (screen);
+  if (gtk_icon_size_lookup_for_settings (settings,
+                                        GTK_ICON_SIZE_DND,
+                                        &width, &height))
+    icon_size = MAX (width, height);
+  else 
+    icon_size = 32; /* default value for GTK_ICON_SIZE_DND */ 
+
+  icon_theme = gtk_icon_theme_get_for_screen (screen);
+
+  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
+                                    icon_size, 0, NULL);
+  set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
+}
+
 /**
  * gtk_drag_set_icon_default:
  * @context: the context for a drag. (This must be called 
index ba52415df87b6a214f7dbd12722054d3d21949a4..e82d6c30630df1532d7c69951f983e4a143d1762 100644 (file)
@@ -112,6 +112,8 @@ void gtk_drag_source_set_icon_pixbuf (GtkWidget   *widget,
                                      GdkPixbuf   *pixbuf);
 void gtk_drag_source_set_icon_stock  (GtkWidget   *widget,
                                      const gchar *stock_id);
+void gtk_drag_source_set_icon_name   (GtkWidget   *widget,
+                                     const gchar *icon_name);
 
 /* There probably should be functions for setting the targets
  * as a GtkTargetList
@@ -143,6 +145,10 @@ void gtk_drag_set_icon_stock  (GdkDragContext *context,
                               const gchar    *stock_id,
                               gint            hot_x,
                               gint            hot_y);
+void gtk_drag_set_icon_name   (GdkDragContext *context,
+                              const gchar    *icon_name,
+                              gint            hot_x,
+                              gint            hot_y);
 
 void gtk_drag_set_icon_default (GdkDragContext    *context);